package pl.edu.pjwstk.kor.sbql4j.project1;

import pl.wcislo.sbql4j.db4o.Db4oSBQLQuery;
import java.util.Collection;
import com.db4o.ObjectContainer;
import pl.edu.pjwstk.kor.database.Database;
import pl.edu.pjwstk.kor.database.Sbql4jQuery;
import pl.edu.pjwstk.kor.model.Customer;
import pl.edu.pjwstk.kor.model.Deal;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Rank;
import pl.edu.pjwstk.kor.model.Service;
import pl.wcislo.sbql4j.java.model.runtime.Struct;

public class Project1Query implements Sbql4jQuery {
    private Database database;
    
    public Project1Query() {
        super();
    }
    
    @Override()
    public void setDatabase(Database db) {
        this.database = db;
    }
    
    /**
     * Wszystkie serwisy gdzie zarobki s\u0105 wi\u0119ksze ni\u017c 5k - where
     * #{ db.(Service where minServiceCost >= 5000.0) }
     */
    public Collection<Service> query1(double serviceCost) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery0(db,serviceCost).executeQuery();
        Collection<Service> services = (Collection<Service>)res;
        return services;
    }
    
    /**
     * Nazwy wszystkich us\u0142ug - kropka
     * #{ db.(Service.serviceName) };
     */
    public Collection<String> query2() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery1(db).executeQuery();
        Collection<String> servicesNames = (Collection<String>)res;
        return servicesNames;
    }
    
    /**
     * Imiona i nazwsiska wszystkich pracowników - przecinek
     * #{ db.(Employee.(firstName, lastName)) }
     */
    public Collection<Struct> query3() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery2(db).executeQuery();
        Collection<Struct> structs = (Collection<Struct>)res;
        return structs;
    }
    
    /**
     * Zni\u017cki z jakimi zawarto umowy - join
     * #{db.(Deal join max(customer.ranks.discount))}
     */
    public Collection<Rank> query4() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery3(db).executeQuery();
        Collection<Rank> ranks = (Collection<Rank>)res;
        return ranks;
    }
    
    /**
     * min, \u015brednia i max zni\u017cka - as
     * <pre>
     * #{ db.(
     *   min(Rank.discount) as minimum,
     *   avg(Rank.discount) as average,
     *    max(Rank.discount) as maximum
     * )};
     * </pre>
     */
    public Struct query5() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery4(db).executeQuery();
        Struct s = (Struct)res;
        return s;
    }
    
    /**
     * Ilo\u015b\u0107 umów zawieranych przez pracowników - group as
     * #{db.(
     *    (Rank as r).(count(r.customers) group as ilosc, r as rank).(ilosc as ilosc, rank as rank)
     * )};
     */
    public Collection<Struct> query6() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project1Query_SbqlQuery5(db).executeQuery();
        return (Collection<Struct>)res;
    }
}